package com.study.guide.codec.protobuf;


import com.study.guide.codec.protobuf.proto.SubscribeReqProto;
import io.netty.channel.ChannelInitializer;
import io.netty.channel.ChannelPipeline;
import io.netty.channel.socket.SocketChannel;
import io.netty.handler.codec.protobuf.ProtobufDecoder;
import io.netty.handler.codec.protobuf.ProtobufEncoder;
import io.netty.handler.codec.protobuf.ProtobufVarint32FrameDecoder;
import io.netty.handler.codec.protobuf.ProtobufVarint32LengthFieldPrepender;

public class TimeServerInitializer extends ChannelInitializer<SocketChannel> {

	@Override
	protected void initChannel(SocketChannel ch) throws Exception {
		ChannelPipeline pl = ch.pipeline(); //连接所有处理器
		pl
				//半包处理
			.addLast(new ProtobufVarint32FrameDecoder())
				// 解码器
			.addLast(new ProtobufDecoder(SubscribeReqProto.SubscribeReq.getDefaultInstance()))
			.addLast(new ProtobufVarint32LengthFieldPrepender())
			.addLast(new ProtobufEncoder())
			.addLast(new TimeServerHandler());
	}

}
